<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>vue-class&style绑定</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        #app{
            display: flex;
            justify-content: space-around;
        }
        .box{
            width: 200px;
            height: 200px;
            background-color: skyblue;
        }
        .active{
            background-color: red;
        }
    </style>
</head>
<body>
    <div id="app">
        <div>
            <h1>对象语法</h1>
            <div class="box" :class='classObject'>
                <p>:class='{active:true}'</p>
                <p>可写在data对象上</p>
            </div>
        </div>

        <div>
            <h1>数组语法</h1>
            <div class="box" :class='[classOne,classTwo]'>
                可用三目符来进行切换
            </div>
        </div>

        <div>
            <h1>用在组件上</h1>
            <my-component class='test'></my-component>
        </div>

    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
    <script>
        Vue.component('my-component',{
            template:`<div class="box"></div>`
        })
        new Vue({
            el:'#app',
            data:{
                classObject:{
                    active:false,
                    test:true,
                },
                classOne:'active',
                classTwo:'test',
            },
        })
    </script>
</body>
</html>